﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QuantitativeInvestment.Bean;
namespace QuantitativeInvestment.CharacterAnalyzer
{
    class MarketValueAnalyzer:CharacterAnalyzer
    {
        public MarketValueAnalyzer()
        {
            this.name = "市值";
            this.factorList.Add(Factor.Factor.createFactorByName("市值"));
        }

        public override void analyse(PortfolioManager portfolioManager)
        {
            string characterFactorName = this.factorList[0].name + "-" + this.factorList[0].paraList["类型"].value.ToString();
            for (int i = 0; i < portfolioManager.soldPortfolioList.Count; i++)
            {
                double sumMarketValue = 0;
                foreach (TradingStock tradingStock in portfolioManager.soldPortfolioList[i].stockList)
                {
                    int curerntPosition = this.container.stocks[tradingStock.code].tradingDateList.IndexOf(tradingStock.buyDate);
                    if (curerntPosition == -1)
                        continue;
                    double[] marketValues = this.container.stocks[tradingStock.code].factors[characterFactorName];
                    sumMarketValue = sumMarketValue + marketValues[curerntPosition];
                }
                Parameter character = new Parameter("平均" + this.factorList[0].paraList["类型"].value.ToString(), sumMarketValue / portfolioManager.soldPortfolioList[i].stockList.Count);

                portfolioManager.soldPortfolioList[i].characterList.Add(character);
            }
        }

        public override void analyse(Portfolio p, Portfolio stockPoolPortfolio = null)
        {

        }
    }
}
